/**
 * 
 */
$(function(){ 
	 getData();
});
function submit(){
	var userName=$("#userName").val();
	var day=$("#day").val();
	if(userName==null ||userName==""){
		layer.msg("请输入userName");
		return ;
	}
	if(day==null ||day==""){
		layer.msg("请输入day");
		return ;
	}
	$.ajax({
		url: "add",
		data: {
			'userName': userName,
			'day': day,
		},
		type: "post",
		async: false,
		success: function(a) {
			layer.msg(a);
		}
	})
	
	 getData();
}

function getData(){
	var b = layer.load(0, {
		shade: false
	});
	layui.use('table', function(){
		  var table = layui.table;
		  table.on('checkbox(demo)', function(obj){
			    console.log(obj)
			});
			//监听工具条
		  table.on('tool(demo)', function(obj){
		    var data = obj.data;
		    if(obj.event === 'del'){
		      layer.confirm('真的删除行么', function(index){
		        obj.del();
		        layer.close(index);
		      });
		    }
		  });
		  table.render({
		    elem: '#demo'
		    ,url:"findAll"
		    ,toolbar: true
		    ,totalRow: true
		    ,cellMinWidth: 80
		    ,cols: [[
		       {type:'checkbox', fixed: 'left'}
		      ,{field:'id', title:'ID',fixed: 'left', unresize: true, sort: true, templet: '#indexTpl' }
		      ,{field:'userName', title:'用户名' }
		      ,{field:'day', title:'天'}
		      ,{field:'hour', title:'时' }
		      ,{field:'minute', title:'分' }
		      ,{toolbar:'#barDemo',title:'操作'}
		    ]]
	    ,even: true //隔行背景
		    ,response: {
		      statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
		    }
		    ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
		      return {
		    	 "code": '200',
		        "count": 5,
		        "data":res
		      };
		    }
		  });
	
		  
		});
	layer.close(b);
}
